package shiyl.use.springboot.requestparam.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件上传的例子
 * @author shiyl
 */
@Slf4j
@RestController
@RequestMapping("/fileupload")
public class FileUploadDemoController {


    /**
     * 请求时content-type设置为multipart/form-data
     * @param multipartFile
     * @return
     */
    @PostMapping(value = "/file1")
    public String demo1(@RequestPart(name = "file1") MultipartFile multipartFile) {
        String content = String.format("name = %s,originName = %s,size = %d",
                multipartFile.getName(), multipartFile.getOriginalFilename(), multipartFile.getSize());
        log.info(content);
        return content;
    }

}
